package com.cskaoyan.catmall.service.Impl;


import com.cskaoyan.catmall.dao.ConfigMapper;
import com.cskaoyan.catmall.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * 创建日期: 2022-01-07-11-50
 * author : XGQ
 * description: ConfigService的实现类
 */
@Component
@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public class ConfigServiceImpl implements ConfigService {

    @Autowired
    ConfigMapper configMapper;

    // 通过关键字key查找对应的value
    @Override
    public String getValue(String market_mall) {
        String value = configMapper.selectByKeyName(market_mall);
        return value;
    }

    // 通过关键字key更新对应的value
    @Override
    public void updateByKeyValue(String market_mall, String value) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String date = df.format(new Date());// new Date()为获取当前系统时间
        int effect = configMapper.updateByKeyValue(market_mall, value, date);
    }
}
